package action;

import dao.CollectDao;
import po.Book;
import po.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(urlPatterns = "/user/action/ShowCollectServlet")
public class ShowCollectServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //从session中获取user
        User user = (User)req.getSession().getAttribute("user");
        CollectDao collectDao = new CollectDao();
        //调用dao层方法
        ArrayList<Book> collects = new ArrayList<Book>();
        collects = collectDao.findByUserId(user.getPhone());
        //绑定数据
        req.setAttribute("collects",collects);
        //转发
        req.getRequestDispatcher("../page/collect.jsp").forward(req,resp);
    }
}
